#include "app/app_buffer.h"
#include <assert.h>
#include <string.h>

int main(void)
{
    char buf[16];
    Buffer buffer;
    memset(&buffer, 0, sizeof(Buffer));

    app_buffer_init(&buffer, 16);
    assert(buffer.size == 16);
    assert(buffer.ptr != NULL);

    app_buffer_write(&buffer, "hello world!", 12);
    assert(buffer.start == 0);
    assert(buffer.len == 12);

    int result = app_buffer_read(&buffer, buf, 4);
    assert(result == 4);
    assert(buffer.start == 4);
    assert(buffer.len == 8);
    assert(strncmp(buf, "hell", 4) == 0);

    app_buffer_write(&buffer, "apex0123", 8);
    assert(buffer.len == 16);

    result = app_buffer_read(&buffer, buf, 14);
    assert(buffer.start == 2);
    assert(buffer.len == 2);
    assert(result == 14);
    assert(strncmp(buf, "o world!apex01", 14) == 0);

    return 0;
}
